package com.publicize.controller;


import com.publicize.commom.commonutils.JwtUtils;
import com.publicize.commom.commonutils.Result;
import com.publicize.entity.ExaminationDetail;
import com.publicize.entity.User;
import com.publicize.entity.Vo.ScoreVo;
import com.publicize.entity.Vo.oneOption;
import com.publicize.service.ExaminationDetailService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
 * <p>
 * 知识竞赛题目表 前端控制器
 * </p>
 *
 * @author bs
 * @since 2021-03-06
 */
@RestController
@RequestMapping("/competition/examination-detail")
@CrossOrigin
public class ExaminationDetailController {
    @Resource
    private ExaminationDetailService examinationDetailService;
//发送试题
@GetMapping("{id}")
public Result sentExamination(@PathVariable String id){
    List<ExaminationDetail> radioOptions=examinationDetailService.sentExamination(id);
    return Result.ok().data("radioOptions",radioOptions);
}
    //统计答案
    @PostMapping
    public Result statisticalScore(@RequestBody ScoreVo scoreVo, HttpServletRequest request){
        //获取用户id
        String userId = JwtUtils.getMemberIdByJwtToken(request);
        Result  userMap=Result.ok();

        return examinationDetailService.statisticalScore(scoreVo,userId,userMap);
    }
    //展示平均分前十排名
    @GetMapping("showRank")
    public Result showRank(){
        List<User> userList=examinationDetailService.showRank();
        return Result.ok().data("userList",userList);
    }
}

